//
// Created by francklinson on 2021/11/20 AT 20:15.
// May Saint Diana bless you!
//

#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <functional>
#include <climits>
#include <string>

using namespace std;

class Solution {
public:
    bool checkPerfectNumber(int num) {
        if (num == 1)
            return false;
        // 找到所有因子 相加 找到1-sqrt(x)即可
        int acc = 1;
        for (int i = 2; i * i <= num; ++i) {
            if (num % i == 0) {
                acc += i;
                if (i * i != num) {
                    acc += num / i;
                }
            }
        }
        return acc == num;
    }
};

int main() {
    Solution solution;
    cout << solution.checkPerfectNumber(28) << endl;
    cout << solution.checkPerfectNumber(6) << endl;
    cout << solution.checkPerfectNumber(496) << endl;
    cout << solution.checkPerfectNumber(8128) << endl;
    cout << solution.checkPerfectNumber(2) << endl;
    cout << solution.checkPerfectNumber(1) << endl;
    return 0;
}

